/**
 * 
 */
package com.qihui.ssh.web.sys;

import com.opensymphony.xwork2.ActionSupport;
import com.qihui.ssh.dao.entities.Employee;
import com.qihui.ssh.service.user.UserService;

/**
 * @author QiHui
 * 
 */
public class LoginAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	UserService userService;

	public String execute() throws Exception {

		Employee user = userService.getUserByUserId(this.getUsername().trim());
		if (user != null && this.getPassword().equals(user.getPassword())) {
			return "success";
		} else {
			this.addFieldError("username", "username or password error");
			return "failer";
		}
	}

	@Override
	public void validate() {
		if (null == this.getUsername() || "".equals(this.getUsername().trim())) {
			this.addFieldError("username", "username required");
		}
		if (null == this.getPassword() || "".equals(this.getPassword().trim())) {
			this.addFieldError("password", "password required");
		}
	}

	private String username;
	private String password;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

}
